#include <cubefs/api/api.hpp>
#include <natives.h>
#include <decls.hpp>
#include <exceptions.hpp>

#include <cubefs/core/tools/types/dispatcher.hpp>

#define CUBEFS_SOURCE "number.cpp:" CUBEFS_AT

using namespace cubefs::api;
using namespace cubefs::tools;

using namespace std;



//Number* convertToNumber(Typed* value) {
//    if (!value->IsInstance(Number::MyType())) {
//        throw TypeCastException(CUBEFS_SOURCE, "Specified value is not a Number: " + value->type()->name(), value->type(), Number::MyType());
//    }
//    else {
//        return static_cast<Number*>(value);
//    }
//}

JNIEXPORT jint JNICALL NUMBER_PKG(Number, getIntValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetIntValue();

    CUBEFS_EXC_HANDLE
    return 0;
}

JNIEXPORT jlong JNICALL NUMBER_PKG(Number, getLongValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetBigIntValue();

    CUBEFS_EXC_HANDLE
    return 0;
}


JNIEXPORT jfloat JNICALL NUMBER_PKG(Number, getFloatValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetFloatValue();

    CUBEFS_EXC_HANDLE
    return 0;
}

JNIEXPORT jdouble JNICALL NUMBER_PKG(Number, getDoubleValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetDoubleValue();

    CUBEFS_EXC_HANDLE
    return 0;
}

JNIEXPORT jshort JNICALL NUMBER_PKG(Number, getShortValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetShortValue();

    CUBEFS_EXC_HANDLE
    return 0;
}

JNIEXPORT jchar JNICALL NUMBER_PKG(Number, getCharacterValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetUShortValue();

    CUBEFS_EXC_HANDLE
    return 0;
}

JNIEXPORT jbyte JNICALL NUMBER_PKG(Number, getByteValue) (JNIEnv *env, jclass, jlong handle) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->GetByteValue();

    CUBEFS_EXC_HANDLE
    return 0;
}



JNIEXPORT void JNICALL NUMBER_PKG(Number, setIntValue) (JNIEnv *env, jclass, jlong handle, jint v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetIntValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setLongValue) (JNIEnv *env, jclass, jlong handle, jlong v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetBigIntValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setFloatValue) (JNIEnv *env, jclass, jlong handle, jfloat v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetFloatValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setDoubleValue) (JNIEnv *env, jclass, jlong handle, jdouble v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetDoubleValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setShortValue) (JNIEnv *env, jclass, jlong handle, jshort v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetShortValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setByteValue) (JNIEnv *env, jclass, jlong handle, jbyte v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetByteValue(v);

    CUBEFS_EXC_HANDLE
}


JNIEXPORT void JNICALL NUMBER_PKG(Number, setCharacterValue) (JNIEnv *env, jclass, jlong handle, jchar v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetUShortValue(v);

    CUBEFS_EXC_HANDLE
}






JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JI) (JNIEnv *env, jclass, jlong handle, jint v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetIntValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JJ) (JNIEnv *env, jclass, jlong handle, jlong v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetBigIntValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JF) (JNIEnv *env, jclass, jlong handle, jfloat v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetFloatValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JD) (JNIEnv *env, jclass, jlong handle, jdouble v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetDoubleValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JS) (JNIEnv *env, jclass, jlong handle, jshort v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetShortValue(v);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JB) (JNIEnv *env, jclass, jlong handle, jbyte v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetByteValue(v);

    CUBEFS_EXC_HANDLE
}


JNIEXPORT void JNICALL NUMBER_PKG(Number, setValue__JC) (JNIEnv *env, jclass, jlong handle, jchar v) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    return value->SetUShortValue(v);

    CUBEFS_EXC_HANDLE
}


JNIEXPORT jint JNICALL NUMBER_PKG(Number, Compare) (JNIEnv *env, jclass, jlong handle, jlong other) {
    CUBEFS_EXC_BEGIN

    Number* value = Handle2Ptr<Number>(handle);
    Number* other_value = Handle2Ptr<Number>(other);
    return value->Compare(other_value);

    CUBEFS_EXC_HANDLE
}


#undef CUBEFS_SOURCE
